1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include <DS1302.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> char buf1[50]; char buf2[50];
LiquidCrystal_I2C lcd(0x27,16,2); DS1302 rtc(14, 15, 16);
void initRTCTime(void) { rtc.writeProtect(false); rtc.halt(false); Time t(2022, 12, 15, 17, 21, 50, 4); rtc.time(t); }
void printTime() { Time tim = rtc.time(); snprintf(buf1, sizeof(buf1), "%04d-%02d-%02d ", tim.yr, tim.mon, tim.date ); snprintf(buf2, sizeof(buf2), "%02d:%02d:%02d", tim.hr, tim.min, tim.sec);
Serial.println(buf1); Serial.println(buf2); }
void setup() { Serial.begin(9600);
initRTCTime(); lcd.init(); lcd.backlight();
lcd.setCursor(0,0); lcd.print(" Clock "); delay(2000); lcd.clear();
}
void loop() { printTime(); delay(1000); Time tim = rtc.time(); lcd.setCursor(0,0); lcd.print(buf1); lcd.setCursor(0,1); lcd.print(buf2); }
|